package com.demo.jwt.controller;

import com.demo.jwt.annotation.UserLogin;
import com.demo.jwt.exception.ResponseVo;
import com.demo.jwt.utils.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/demo")
public class DemoController {

    @GetMapping("/test")
    @UserLogin
    public ResponseVo<String> test(){
        return ResponseVo.ok("ok");
    }

    @GetMapping("/login")
    public ResponseVo login(String username, String password){
        Map<String,Object> map = new HashMap<>();
        String token = JwtUtil.getToken(UUID.randomUUID().toString().replaceAll("-", ""), username);
        map.put("token",token);
        return ResponseVo.ok(map);
    }
}
